package com.ksu.manager.dao.ibatisImpl;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;

import com.ksu.manager.dao.IUserDAO;
import com.ksu.manager.model.User;

public class UserDAOImpl extends SqlSessionDaoSupport implements IUserDAO {

	public void create(User user) {
		try {
			this.getSqlSession().insert("user.insert",user);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void delete(User user) {
		try {
			this.getSqlSession().delete("user.delete",user);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@SuppressWarnings("unchecked")
	public List<User> queryList(User user) {
		List<User> userList = null;
		try {
		    if(user==null){
		    	user = new User();
		    }
		    userList = (List<User>)this.getSqlSession().selectList("user.select",user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return userList;
	}

	public void update(User user) {
		try {
			this.getSqlSession().update("user.update",user);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public User queryUserById(User user) {
		try{
			user = (User)this.getSqlSession().selectOne("user.selectById", user);
		}catch(Exception e){
			e.printStackTrace();
		}
		return user;
	}

}
